import psycopg2

# 连接到 PostgreSQL 数据库
conn = psycopg2.connect(
    dbname="nmg_info",
    user="postgres",
    password="此处填写数据库密码",
    host="localhost",
    port="5432"
)
cursor = conn.cursor()

# 使用 SELECT 语句查询数据
cursor.execute('''
               SELECT *
               FROM population.population_info
               ''')

# 获取所有查询结果
rows = cursor.fetchall()

# 输出每一条记录
for row in rows:
    print(row)

# 关闭连接
conn.close()
